<?php
/* OpenBIBLIO -- A library administration web interface
 * Copyright (C) 2002-2005 Fr&eacute;d&eacute;ric Descamps <lefred@tiscali.be>
 * Copyright (C) 2011-2012 Laurent Luyssen   <big.lol13@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

include_once("includes/db.inc");
include_once("includes/functions.inc");
include ("includes/header.inc");

function display_etat($etat_ID = 0) {
    $requete = "select * from etats where id=$etat_ID";
    if(!($resultat = biblio_db_query($requete))) {
    	print "PROBLEME : " .biblio_db_error(); 
    }
    else {
    	while ($row = biblio_db_fetch_array($resultat)) {
			$etat_id = $row['id'];
			$etat_nom =  $row['etat'];
			$etat_value = $row['value'];
        }
    }
    $bg = array("#ff0000", "#fd1006", "#fe6b10", "#fe7a12", "#fed01d", "#feea20", "#e5fe26", " #b4fe2e", "#7fff36", "#33ff00", "#65ff3b");
    foreach ($bg as $key => $value) {
        echo '<span style="background-color: '.$value.'"><input type=radio name=etat_value value='.$key;
	    if ($etat_value == $key) 
	    	echo " checked"; 
	    else 
	    	echo " disabled"; 
    	echo '>'.$key.'</span>';
    }
}

if (isset($_GET['id']))
	$id = $_GET['id'];
if (!empty($id)) {
	$row = get_book($id);
	if (!$row) {
		print "PROBLEME : " .biblio_db_error();
		exit(); 
	}
    $liv_resume = $row['resume'];
	$liv_motclefs =  $row['motclefs'];
	$liv_nom = $row['nom'];
	$liv_num = $row['num'];
	$liv_auteur = $row['auteur'];
	$liv_ISBN = $row['ISBN'];
	$liv_id = $row['id'];
	$liv_collection = $row['collection'];
	$liv_edition = $row['edition'];
	$date_ed = $row['date_ed'];
	$genre_ID = $row['genre_ID'];
	$etat_ID = $row['etat_ID'];
	$location_ID = $row['location_ID'];
	$liv_temp = $row['temp'];
    $liv_noout = $row['noout'];
    $import_Id = $row['import_ID'];

    echo "<br><div id=tabsearch><CENTER>";
    echo "<H3>$liv_nom";
    if ($liv_num)
    	echo "($liv_num)";
    echo "</H3><i>$liv_auteur</i></CENTER>";
    if (file_exists("images/covers/$liv_id.jpg"))
	    echo "<img src=images/covers/$liv_id.jpg align=right>";
	    	    
	echo "<table>";
    echo "<tr><td><B>";
    echo _("Collection");
    echo "</B></td><td><i>$liv_collection </i></td></tr>";

    echo "<tr><td><B>";
    echo _("Edition");
    echo "</B></td><td><i>$liv_edition </i></td></tr>";

    echo "<tr><td><B>";
    echo _("Date");
    echo "</B></td><td><i>$date_ed</i></td></tr>";

    echo "<tr><td><B>";
    echo _("Genre");
    $genre = get_genres(" where id=$genre_ID ");
    echo "</B></td><td><i>".$genre[$genre_ID]."</i></td></tr>";

    echo "<tr><td><B>";
    echo _("R&eacute;sum&eacute;");
    echo "</B></td><td><i>$liv_resume</i></td></tr>";

    echo "<tr><td><B>";
    echo _("Mots clefs");
    echo "</B></td><td><i>$liv_motclefs</i></td></tr>";

    echo "<tr><td><B>";
    echo _("Etat");
    echo "</B></td><td>";
    display_etat($etat_ID);
    echo "</td></tr>";

    echo "<tr><td><B>";
    echo _("Location");
    $loc = get_locations(" where id=$location_ID ");
    echo "</B></td><td><i>".$loc[$location_ID]."</i></td></tr>";

    echo "<tr><td><B>";
    echo _("Temporaire");
    echo "</B></td><td><i>";
    if ($liv_temp == 0)
    	echo _("Non");
    else 
    	echo _("Oui");
    echo "</i></td></tr>";

    echo "<tr><td><B>";
    echo _("Ne peux sortir !");
    echo "</B></td><td><i>";
    if ($liv_noout == 0)
    	echo _("Non");
    else 
    	echo _("Oui");
    echo "</i></td></tr>";
	
    echo "<tr><td><B>";
    echo _("ISBN");
    echo "</B></td><td><i>$liv_ISBN</i></td></tr>";

	if (isset($import_Id)) {
		echo "<tr><td><B>";
		echo _("Import ID");
		echo "</B></td><td><i>$import_Id</i></td></tr>";
	}
	
	echo "</table>";

	// Borrower history
	$req  = "SELECT id, emprunteur, date_out, date_in FROM prets2 WHERE livre_ID=$id ORDER BY id DESC";
	$result = biblio_db_query($req);
	if (!$result) {
		print "PROBLEME : ".biblio_db_error()."<br>$req"; 
		exit();
	}

	if (biblio_db_num_rows($result) > 0) {
		$i = 0;
		echo "<HR><H2>"._("Historique des emprunts")."</H2><BR/>";
		echo '<table class="search_results"><th>';
		echo _("Date pr&ecirc;t");
		echo "</th><th>";
		echo _("Date retour");
		echo "</th><th>";
		echo _("Emprunteur");
		echo "</th>";
		while ($row = biblio_db_fetch_array($result)) { 
			$borrower = $row['emprunteur'];
			$date_out = $row['date_out'];
			$date_in  = $row['date_in'];
			if ($i%2 == 1)
            	$style = "odd";
            else 
            	$style = "even";
			echo "<tr class=\"$style\"><td>$date_out</td><td>$date_in</td><td>$borrower</td></tr>";
			$i++;
		}
		echo "</table>";
	}
	
    echo "<BR></div><BR><A HREF=\"javascript:self.close();\">";
    echo _("Fermer");
    echo "</A>";
}
else {
 print "<H3>". _("Un livre doit &ecirc;tre choisi !") ."</H3>";
}
?>
<br/><br/>
<div>
<span id=left-text>
<A HREF="index.php">
<?php echo _("retour menu principal"); ?>
</A></span>
</div>
<br>
<?php
include("includes/footer.inc");
?>
